<template>
	<view class="cart-container">
		<!-- 收获地址组件 -->
		<my-address></my-address>
		<!-- 商品列表的标题区域 -->
		<view class="cart-title">
			<uni-icons type="shop" size="18"></uni-icons>
			<text class="cart-title-text">购物车</text>
		</view>
		
		<!-- 循环渲染购物车中商品信息 -->
		<uni-swipe-action>
			<block v-for="(goods, i) in cart" :key="i">
			  <uni-swipe-action-item :right-options="options" @click="deleteCartItem(goods)">
				<my-goods :item="goods" showNum="true" showRadio="true" @radio-change="radioChangeHandler"
				@num-change="numChangeHandler"></my-goods>
			  </uni-swipe-action-item>
			</block>
		</uni-swipe-action>
		<my-settle></my-settle>
	</view>
</template>

<script>
import badgeMix from '@/mixins/tabbar-badge.js'
import {mapState,mapMutations,mapGetters} from 'vuex'
	export default {
		mixins:[badgeMix],
		computed:{
			...mapState('m_cart',['cart']),
			...mapGetters('m_cart',['total'])
		},
		watch:{
			total(newVal){
				this.setBadge()
			}
		},
		data() {
			return {
				options:[{
					text:'删除',
					style:{
						backgroundColor:'#C00000'
					}
				}]
			};
		},
		methods: {
			...mapMutations('m_cart',['updateGoodsState','updateGoodsNum','removeGoodsById']),
			radioChangeHandler(e){
				this.updateGoodsState(e)
			},
			numChangeHandler(e){
				this.updateGoodsNum(e)
			},
			deleteCartItem(goods){
				this.removeGoodsById(goods.goods_id)
			}
		}
	}
</script>

<style lang="scss">
.cart-container{
	padding-bottom: 50px;
}
.cart-title{
	height: 40px;
	display: flex;
	align-items: center;
	padding-left: 5px;
	border-bottom: 1px solid #efefef;
	.cart-title-text{
		font-size: 14px;
		margin-left: 10px;
	}
}
</style>
